package uw.illno.controller


import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import uw.illno.service.AdministratorService
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import kotlin.Throws
import java.io.IOException
import uw.illno.pojo.Student

@Controller
class StudentpwdReset {
    @Autowired
    private lateinit var service: AdministratorService

    @RequestMapping(value = ["/sreset"], method = [RequestMethod.POST])
    @Throws(IOException::class)
    fun sreset(model: Model, sno: String): String {
        when (sno) {
            "" -> {
                model.addAttribute("msgr", "学号不能为空！")
                return "adpages/adminindex"
            }
            else -> {
                val student = Student()
                student.sno = sno
                val result = service.resetpwd(student)
                return if (result > 0) {
                    model.addAttribute("msgr1", "重置密码成功！初始密码为：123456!")
                    "adpages/adminindex"
                }
                else {
                    model.addAttribute("msgr", "查无此人，请检查学号是否正确！")
                    "adpages/adminindex"
                }
            }
        }
    }
}
